package com.example.day02.mefrag;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.GridView;

import com.example.day02.MainActivity;
import com.example.day02.R;
import com.example.day02.luckfrag.FortuneActivity;
import com.example.day02.startfrag.StarInfo;
import com.example.day02.utils.AssetsUtils;
import com.google.gson.Gson;

import java.util.List;

public class LogoActivity extends Activity {
    GridView logoGv;
    private LogoAdapter adapter;
    List<StarInfo.StarinfoBean> list;
    private static final String TAG = "LogoActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //requestWindowFeature( Window.FEATURE_NO_TITLE );//去掉标题栏，不明白删掉跑一遍就明白了
        setContentView(R.layout.activity_logo);
        logoGv=findViewById(R.id.logo_gv);
        //        读取assets/xzcontent/xzcontentlogo.json文件
        String json = AssetsUtils.getJsonByAssets(this, "xzcontent/xzcontent.json");
//        将json字符串转换成创建类的对象
        Gson gson = new Gson();
        StarInfo starInfo = gson.fromJson(json, StarInfo.class);
        //将assets文件夹操作
        AssetsUtils.saveLogoBitmapFromAssets(this,starInfo);

        list = starInfo.getStarinfo();
        adapter = new LogoAdapter(this, list);
        logoGv.setAdapter(adapter);
        logoGv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();

                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setClass(LogoActivity.this, MainActivity.class);//跳转后不返回
                intent.putExtra("star_name",list.get(position).getName());
                Log.d(TAG, "name: "+list.get(position).getName());
                intent.putExtra("star_logo_name",list.get(position).getLogoname());
                Log.d(TAG, "star_logo_name: "+list.get(position).getLogoname());
                intent.putExtra("id",1);
                startActivity(intent);

            }
        });

    }
}
